package com.studio701.carguard.controller;


import com.studio701.carguard.pojo.Report;
import com.studio701.carguard.pojo.RespBean;
import com.studio701.carguard.service.IReportService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xjc
 * @since 2022-04-08
 */
@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    IReportService iReportService;

    @ApiOperation("添加报表")
    @PostMapping("/")
    public boolean insertReport(@RequestBody Report report){
        return iReportService.save(report);
    }

    @ApiOperation("获取报表")
    @GetMapping("/")
    Report getById(Integer id){
        return iReportService.getById(id);
    }

    @ApiOperation("更新报表")
    @PutMapping("/")
    RespBean updateReport(@RequestBody Report report){
        if(iReportService.updateById(report)){
            return RespBean.success("更新成功");
        }else {
            return RespBean.success("更新失败");
        }
    }

    @ApiOperation("获取用户所有报表")
    @GetMapping("/{id}")
    List<Report> getReports(@PathVariable("id") Integer id){
        return iReportService.getReports(id);
    }

    @ApiOperation("获取最近一次报表")
    @GetMapping("/recent/{id}")
    Report getRecentReport(@PathVariable("id") Integer id){
        return iReportService.getRecentReport(id);
    }
}
